"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
//装饰器
console.log("------------装饰器--------------");
//类的装饰器
//装饰器
function addFrom(constructor) {
    console.log("1111111111111类装饰器（addFrom）1111111111111111");
    //constructor构造函数
    console.log(constructor);
    constructor.prototype.from = "中国";
}
//传参的装饰器
function addAddress(address) {
    console.log("22222222222类装饰器（addAddress）2222222222222");
    return function (constructor) {
        constructor.prototype.address = address;
        constructor.prototype.getAddress = function () {
            console.log(this.name + " " + this.address);
        };
    };
}
//方法装饰器
function getNameMethod(target, methodName, descriptor) {
    console.log("1111111111111方法装饰器1111111111111111");
    console.log("target", target);
    console.log("methodName", methodName);
    console.log("descriptor", descriptor);
    //descriptor属性描述符
    target.id = 10000;
    // target.prototype.id=20000;
    descriptor.value = function () {
        console.log("装饰的方法");
    };
    // descriptor.writable=true;
}
//检验电话号的方法装饰器
function checkMobile(target, methodName, descriptor) {
    let fn = descriptor.value;
    descriptor.value = function (arg) {
        if (!arg) {
            console.log("请输入电话号");
            return;
        }
        else if (!(/^1[3456789]\d{9}$/.test(arg))) {
            console.log("电话号码格式不正确");
            return;
        }
        else {
            //call改变this指向
            fn.call(this, arg); //执行原先方法
        }
    };
}
//属性装饰器
function linkNameValue(parmas) {
    console.log("1111111111111属性 饰器1111111111111111");
    return function (target, propertyName) {
        console.log("-----属性装饰器----");
        console.log("target", target);
        console.log("propertyName", propertyName);
        target[propertyName] = parmas;
        // target.linkName=parmas;
    };
}
//参数的装饰器
function mobileDec(target, methodName, index) {
    console.log("1111111111111参数饰器1111111111111111");
    console.log("-----参数装饰器----");
    console.log("target", target);
    console.log("methodName", methodName);
    console.log("index", index);
}
let Company = class Company {
    constructor(name) {
        this.name = name;
        this.mobile = "";
        // this.linkName="";
    }
    setMobile(mobile) {
        this.mobile = mobile;
        console.log("给电话赋值");
    }
    getName() {
        console.log("类里的方法");
    }
    setInfo(name, mobile) {
        console.log("设置信息");
        this.name = name;
        this.mobile = mobile;
    }
};
__decorate([
    linkNameValue("张三")
], Company.prototype, "linkName", void 0);
__decorate([
    checkMobile
], Company.prototype, "setMobile", null);
__decorate([
    getNameMethod
], Company.prototype, "getName", null);
__decorate([
    __param(1, mobileDec)
], Company.prototype, "setInfo", null);
Company = __decorate([
    addFrom,
    addAddress("北京市昌平区")
], Company);
let comapny = new Company("百度");
console.log(comapny.from);
console.log(comapny.address);
comapny.getAddress();
console.log(comapny.id);
// comapny.getName=function(){
//     console.log("外部重写了方法");
// }
//报错 因为方法装饰器  禁止了 外部重写 getName方法
comapny.getName();
comapny.setMobile("99999");
console.log(comapny.mobile);
console.log("联系人", comapny.linkName);
// @addAddress("北京市海淀区")
// class Company2{
//     name:string;
//     constructor(name:string){
//         this.name = name;
//     }
// }
// let company2:any=new Company2("百度");
// company2.getAddress();
